package com.fone.player.service;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.os.RemoteException;

import com.fone.player.constant.FoneConstant;
import com.fone.player.util.L;

/**
 * 服务管理类(唯一)
 * 
 * @author JasonZue
 * @since 2014-5-19
 */

public class FoneServiceManager {
	public static final String TAG = "FoneServiceManager";

	public static FoneServiceManager sFoneServiceManager;

	private SharedPreferences mSp;

	public Context mContext;

	private FoneServiceManager(Context context) {
		this.mContext = context;
	}

	/**
	 * 获取服务管理类实例
	 * 
	 * @param context
	 * @return FoneServiceManager
	 * @throws
	 */
	public static FoneServiceManager getFoneServiceManager(Context context) {
		if (sFoneServiceManager == null) {
			sFoneServiceManager = new FoneServiceManager(context);
			sFoneServiceManager.mSp = context.getSharedPreferences(FoneConstant.FONE_SP_NAME_SP, Context.MODE_PRIVATE);
		}
		return sFoneServiceManager;
	}

	// 开启通知独立的service
	public void startNotificationService() {
		L.v(TAG, "startNotificationService", "---start----");

		if (mSp.getBoolean(FoneConstant.NOTIFY_AUTO_OPEN_FLAG_SP, true)) {
			Intent notificationService = new Intent();
			notificationService.setClass(mContext, NotificationService.class);
			mContext.startService(notificationService);
		}

	}

	// 关闭通知service
	public void stopNotificationService() {
		L.v(TAG, "stopNotificationService", "---stop----");
		Intent notificationService = new Intent();
		notificationService.setClass(mContext, NotificationService.class);
		mContext.stopService(notificationService);
	}

	/**
	 * 加载apk
	 * 
	 * @param url
	 * @param showInfo
	 * @return void
	 * @throws
	 */
	public void loadAPK(final String url, final String showInfo) {

		Intent intent = new Intent(mContext, FoneService.class);
		intent.putExtra("type", FoneService.TYPE_LOADAPKBYURL);
		intent.putExtra("url", url);
		intent.putExtra("showInfo", showInfo);
		mContext.startService(intent);

	}
}
